// pages/password/password.js  
//获取应用实例  
var app = getApp();
var ImageURL = app.globalData1.ImageURL;
var hostURL = app.globalData1.hostURL;


Page({

  data: {
    userinfo: ''

  },


  formSubmit: function (e) {
    console.log(e);
    var phone = e.detail.value.phone;
    var oldpwd = e.detail.value.oldpwd;
    var newpwd = e.detail.value.newpwd;
    var newpwd2 = e.detail.value.newpwd2;

    if (oldpwd == '' || newpwd == '' || newpwd2 == '') {
      wx.showToast({
        title: '密码不能为空',
        icon: 'none',
        duration: 1000
      })
    } else if (newpwd != newpwd2) {
      wx.showToast({
        title: '两次密码输入不一致',
        icon: 'none',
        duration: 1000
      })
    } else {
      // var url = "https://www.lishuming.top/pj/index.php/student/api/setpassword";  
      wx.showLoading({
        title: '网络请求中......',
      })
      wx.request({
        url: hostURL + "sharedplatform-web/user/alterPassworder.action",
        method: 'POST',
        data: {
          phone: phone,
          // oldpwd: oldpwd,
          newPassword: newpwd
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {

          if (res.data.errno == 0) {
            wx.showToast({
              title: "修改密码成功",
              success: function () {
                setTimeout(function () {
                  wx.navigateTo({
                    url: '../login/login',
                  })
                }, 2000)
              }

            })
          } else {
            wx.showToast({
              title: "修改密码失败",
            })
          }
        }
      })
    }
  },


})  